package com.hefei.edu.controller;


import com.hefei.common.utils.R;
import com.hefei.edu.service.ISubjectService;
import com.hefei.edu.vo.Tree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author caizhengjun
 * @since 2021-03-04
 */
@RestController
@RequestMapping("/edu/subject")
public class SubjectController {

    @Autowired
    private ISubjectService subjectService;

    @PostMapping("/add/excel")
    public R addSubject(MultipartFile file) {

        this.subjectService.saveExcel(file);

        return R.ok().message("Excel文件读取成功！");
    }

    @PostMapping("/write/excel")
    public R write() {

        this.subjectService.writeExcel();

        return R.ok().message("写入成功！");
    }

    @GetMapping("/tree")
    public R tree() {

        List<Tree> tree = this.subjectService.tree();

        return R.ok().message("获取数据成功！").data(tree);
    }
}

